/* 
 * File:   gArrayList.h
 * Author: jorge
 *
 * Created on April 24, 2013, 10:58 AM
 */

#ifndef GARRAYLIST_H
#define	GARRAYLIST_H
#include <string.h>

template<class E>
class GArrayList
{
public:

    GArrayList()
    {
        this->size_ = 0;
        this->capacity_ = 50;
        this->data_[50];
    }

    GArrayList(int capability)
    {
        this->size_ = 0;
        this->capacity_ = capability;
        this->data_[capability];
    }

    ~GArrayList()
    {
        //        if (this->size_ > 0)
        //        {
        //            for(int i = 0; i < size_; i++)
        //            {
        //                delete &this->data_[i];
        //            }
        //            
        //            delete [] this->data_;
        //        }
    }

    int size()
    {
        return this->size_;
    }

    void add(E t)
    {
        if (this->capacity_ > size_)
        {
            this->data_[size_] = t;
            this->size_++;
        } else
        {
            resize();
            add(t);
        }
    }

private:

    void resize()
    {
        this->capacity_ *= 2;
        E copy [this->capacity_];

        for (int i = 0; i < this->size_; i++)
        {
            copy[i] = this->data_[i];
        }
        
        memcpy(this->data_, copy, this->size_);
    }
private:
    int size_;
    int capacity_;
    E data_[50];
};

#endif	/* GARRAYLIST_H */

